package net.huashitong.index.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.index.entity.EnterpriseEntity;
import net.huashitong.index.filter.EnterpriseFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class EnterpriseDao extends StringDao<EnterpriseEntity> {

    public List<EnterpriseEntity> queryByFilterNoPage(EnterpriseFilter filter){
        GenericQuery query = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getAddress())){
            query.append(" and address like:address").setParam("address",
                    StringUtils.getLikewords(filter.getAddress()));
        }
        if(StringUtils.isNotBlank(filter.getBusinessScope())){
            query.append(" and businessScope like:businessScope").setParam("businessScope",
                    StringUtils.getLikewords(filter.getBusinessScope()));
        }
        if(StringUtils.isNotBlank(filter.getEmail())){
            query.append(" and email =:email").setParam("email",
                    filter.getEmail());
        }
        if(StringUtils.isNotBlank(filter.getEnterpriseName())){
            query.append(" and enterpriseName like:enterpriseName").setParam("enterpriseName",
                    StringUtils.getLikewords(filter.getEnterpriseName()));
        }
        if(StringUtils.isNotBlank(filter.getLegalPerson())){
            query.append(" and legalPerson like:legalPerson").setParam("legalPerson",
                    StringUtils.getLikewords(filter.getLegalPerson()));
        }
        return  query.listResult();
    }
}
